<?php

Class Product_Sex {
    
    /*
     * 数据表名
     */
    const TABLE_NAME = 'product_sex';

    /**
     * 缓存实例
     *
     * @var Helper_Cache_Memcache
     */
    protected $_cacheInstance;
    /**
     * db实例
     *
     * @var Helper_Cache_Memcache
     */
    protected $_dbInstance;
    /**
     * 单例对象
     */
    public static $singletonObjects;

    /**
     * 获取单例
     */
    public static function getInstance() {
        $className = __CLASS__;
        if (!isset(self::$singletonObjects[$className])) {
            self::$singletonObjects[$className] = new self();
        }

        return self::$singletonObjects[$className];
    }

    /**
     * 构造器
     *
     * @param int $uId
     */
    protected function __construct() {

//        $this->_cacheInstance = $this->_getCache();
        $this->_dbInstance = $this->_getMysql();
    }

    /*
     * 获取cache实例
     */

    public function _getCache() {

        return Common::getCache();
    }

    /*
     * 获取db实例
     */

    public function _getMysql() {

        return Common::getMysql();
    }

    
    /**
     * 根据产品ID
     * 返回此ID产品消费层次
     */
        public function getSexId ( $pid ) {
        
        $table = self::TABLE_NAME;
        $where = 'PId ='.$pid;
        return $this->_dbInstance ->getList($table, $where);
        
    }
    
    /**
     * 获取指定性别的产品
     */
    public function getSexProduct ($field , $table,$whereSex) {
        
        if ( $whereSex ) {
            return $this->_dbInstance->getListTo($field ,$table, $whereSex);
        } 
    }
      /**
       * 添加到product_Sex
       */
       public function addProductSex( $pid ,$sex ){
          foreach( $sex as $key =>$value){
            Common::getMysql()->add( self::TABLE_NAME ,array( 'PId'=>$pid ,'DId'=>$value));
          }
          
      }
      /**
       *删除produt_sex
       * @param type $pid
       * @return type 
       */
    public function delProduct( $pid ){
        $productSex = Common::getMysql()->delete( self::TABLE_NAME , array( 'PId' => $pid));
        return $productSex;
        
    }

     public function productSex( $pid ){
          $productId = Common::getMysql()->getList( self::TABLE_NAME , array( 'PId' => $pid));
          foreach( $productId as $key => $value){
              $productInfo[] = dimensions_Info::getInstance()->getDimensions( $value['DId'] );
              
          } 
          foreach( $productInfo as $key => $value){
                $arrSex[] = $value['DId'];
                
            }
            return $arrSex;
        
    }
    public function __destruct() {
        
    }


}

?>